package interpreters;

import java.util.*;

import org.hibernate.*;
import dataObjects.*;
import definitions.Conflict;

public class DetailedScheduleGenerator {
	public static String[] dayStrings = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; //maintained in this class so I can associate the index with the correct day.
	public String[][] dailyDoses = new String[7][];//First index is the day of the week, 0-Sunday through 6-Saturday, second index is the ith dose information.
	//So, days[0][5] is the 6th dosage item on Sunday.
	
	public static void main(String[] args){
		LinkedList<LinkedList<String>> list = getEvents("woodsd");
		System.out.println("Printing Doses...\n");

		System.out.println("---------------------");
		for(LinkedList<String> l:list){
			for(String s:l){
				System.out.println(s);
			}
			System.out.println("---------------------");
		}
		System.out.println("Done Printing Doses...\n");
	}
	
	public static LinkedList<LinkedList<String>> getEvents(String userName){
		DoseId id;
		
		List<Dose> doses;
		DoseDAO doseDao = new DoseDAO();
		Transaction tx = doseDao.getSession().beginTransaction();
		tx.commit();
		doseDao.getSession().close();
		tx = doseDao.getSession().beginTransaction();
		doses = doseDao.findByUserName(userName);
		tx.commit();
		doseDao.getSession().close();
		
		//Initialize my 7 LinkedLists of dosing information
		LinkedList<LinkedList<String>> dailySchedules = new LinkedList<LinkedList<String>>();
		for(int i = 0; i < 7; i++) dailySchedules.add(new LinkedList<String>());
		
		//Iterate through all doses for the supplied user.  
		for(Dose d:doses){ // Gets all high level medicine dosing schedule objects
			//for each dose, split out the individual times to an array of Strings...
			String[] times = d.getFrequency().split(",");
			//...and iterate
			for(String t:times){
				//Split on the dash to separate day of week and minutes past midnight
				String[] texp = t.split("-");

				System.out.printf("{0} | {1}\n", t, texp[0]);
				//and add the string medicineName-day_of_week-minutes_past_midnight-amount-unit to the LinkedList whose index matches the day
				//given doseInfo, 0:Medicine Name, 1:Day, 2: Minutes, 3:Amount, 4: Units
				String toAdd = d.getId().getMedicine() + "-" + t + "-" + d.getAmount() + "-" + d.getUnit();
				int day = Integer.parseInt(texp[0].trim());
				System.out.println(toAdd);
				dailySchedules.get(day).add(toAdd);
			}
		}
		
		return dailySchedules;
	}
	
}
